@extends('admin::layouts.master')
@section('content')
    @component('components.tabs',['title' => "栏目管理"])
        @slot('nav')
            <li class="nav-item"><a class="nav-link active" href="/article/category">栏目列表</a>
            </li>
            <li class="nav-item"><a class="nav-link"  href="/article/category/create">添加栏目</a></li>
        @endslot
        @slot('body')
            <div class="panel-body">
                <table class="table">
                    <thead>
                    <tr>
                        <th style="width:10%;">编号</th>
                        <th style="width:20%;">栏目名称</th>
                        <th class="">添加时间</th>
                        <th class="">修改时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($categories as $category)
                        <tr>
                            <td>{{$category['id']}}</td>
                            <td>{!!$category['_name']  !!}</td>
                            <td>{{$category['created_at']}}</td>
                            <td>{{$category['updated_at']}}</td>
                            <td>
                                <div class="btn-group">
                                    <a href="/article/category/{{$category['id']}}/edit" class="btn btn-primary">编辑</a>
                                    <button type="button" class="btn btn-danger" onclick="delCategory(this)">删除</button>
                                    <form action="/article/category/{{$category['id']}}" method="post">
                                        @csrf
                                        @method('DELETE')
                                    </form>
                                </div>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        @endslot
    @endcomponent
@endsection
@section('scripts')
    <script>
        function delCategory(btn) {
            if (confirm('确定要删除栏目吗？')) {
                $(btn).next('form').trigger('submit')
            }
        }
    </script>

@endsection
